//
//  parentCheckList.m
//  ChatDemo-UI2.0
//
//  Created by syun on 16/3/22.
//  Copyright © 2016年 syun. All rights reserved.
//

#import "parentCheckList.h"
#import "ParentCheckTableViewCell.h"
@implementation parentCheckList
NSArray *studentArr;
NSMutableArray *mustudentArr;
-(id)initWithFrame:(CGRect)frame setClassId:(NSString *)classId setMonthId:(NSString *)monthId
{
    self=[super initWithFrame:frame];
    if (self) {
        [self loadTableView:classId setMonthId:monthId];
    }
    return self;
}
-(void)loadTableView:(NSString *)classid setMonthId:(NSString *)monthid
{
    
    UIButton *classBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    classBtn.frame=CGRectMake(10, 0, (self.frame.size.width-20)*0.6, 30);
//    [classBtn addTarget:self action:@selector(chooseClassTouchAction:) forControlEvents:UIControlEventTouchUpInside];
//    classBtn.backgroundColor=[UIColor greenColor];
//    [self addSubview:classBtn];
//    
//    UIButton *timeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
//    timeBtn.frame=CGRectMake(classBtn.frame.origin.x+classBtn.frame.size.width+10,classBtn.frame.origin.y, (self.frame.size.width-20)*0.4-10, 30);
//    [timeBtn addTarget:self action:@selector(chooseTimeTouchAction:) forControlEvents:UIControlEventTouchUpInside];
//    timeBtn.backgroundColor=[UIColor greenColor];
//    [self addSubview:timeBtn];
    
    UILabel *label01=[[UILabel alloc]initWithFrame:CGRectMake(10, classBtn.frame.origin.y+classBtn.frame.size.height+10,(self.frame.size.width-20)*0.6, 30)];
    label01.text=@"时间";
    label01.textAlignment=NSTextAlignmentCenter;
    label01.backgroundColor=[UIColor whiteColor];
    [self addSubview:label01];
    UILabel *label02=[[UILabel alloc]initWithFrame:CGRectMake(label01.frame.origin.x+label01.frame.size.width, label01.frame.origin.y,(self.frame.size.width-20)*0.4, 30)];
    label02.text=@"到校情况";
    label02.textAlignment=NSTextAlignmentCenter;
    label02.backgroundColor=[UIColor whiteColor];
    [self addSubview:label02];
    
    
    _myTableView=[[UITableView alloc]initWithFrame:CGRectMake(10, label01.frame.origin.y+label01.frame.size.height+1, self.frame.size.width-20, self.frame.size.height-label01.frame.size.height-classBtn.frame.size.height-50) style:UITableViewStylePlain];
    _myTableView.tableFooterView=[[UIView alloc]init];
    _myTableView.dataSource=self;
    _myTableView.delegate=self;
    [self addSubview:_myTableView];
    
    emptyView = [[EmptyStateView alloc] initWithFrame:CGRectMake(0, (SCREENHEIGH-110)/2-70, _myTableView.frame.size.width, 110) andBackImage:@"myfriend_empty" andBottomStr:@"暂无点到记录"];
    [_myTableView addSubview:emptyView];
    
    [self loadStudentData:classid mouthId:monthid];
    
}
-(void)loadStudentData:(NSString *)cid mouthId:(NSString *)mid
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"sy_rollcall_inlist" forKey:@"method"];
    [dict setObject:cid forKey:@"classid"];
    [dict setObject:mid forKey:@"date"];
    [dict setObject:USERID forKey:@"userid"];
    [dict setObject:@"1" forKey:@"type"];
    [dict setObject:@"10000" forKey:@"pagesize"];
    [dict setObject:@"1" forKey:@"pageno"];

    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        studentArr=[NSArray array];
        [mustudentArr removeAllObjects];
        NSDictionary *dict = (NSDictionary *)resposeJson;
        studentArr=[dict objectForKey:@"re_data"];
        if (studentArr.count>0) {
            studentArr=[ConfirmationNsnull nullArr:studentArr];
        }
        mustudentArr=[NSMutableArray arrayWithArray:studentArr];
        if (mustudentArr.count>0) {
//            [self->nodataImage removeFromSuperview];
            [self->emptyView hideEmptyImage];
        }else
        {
            [self->emptyView showEmptyImage];
//            if(!self->nodataImage)
//            {
//                self->nodataImage=[[UIImageView alloc]initWithFrame:CGRectMake((self->_myTableView.frame.size.width-95)/2, (self->_myTableView.frame.size.height-95)/2, 95, 95)];
//            }
//            self->nodataImage.image=[UIImage imageNamed:@"nodata"];
//            [self->_myTableView addSubview:self->nodataImage];

        }
        [self->_myTableView reloadData];
        
    } failure:^(NSInteger recode, NSError * error){
        
    }];

}
-(void)chooseClassTouchAction:(UIButton *)sender
{
    
}
-(void)chooseTimeTouchAction:(UIButton *)sender
{
    
}

#pragma mark - UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [mustudentArr count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIndentifier = @"cell";
    ParentCheckTableViewCell *cell =(ParentCheckTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    if (cell==nil) {
        cell =[[[NSBundle mainBundle]loadNibNamed:@"ParentCheckTableViewCell" owner:nil options:nil] objectAtIndex:0];
    }
   
    cell.timelabel.text=[[[mustudentArr objectAtIndex:indexPath.row] objectForKey:@"time"] substringToIndex:10 ];
    cell.markImag.image=[UIImage imageNamed:@"到校"];
    return cell;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
